package com.zh.mediaservice.mapper;

import com.zh.mediapojo.entity.Order;

import com.zh.mediapojo.vo.NotPayVO;
import com.zh.mediapojo.vo.PayNotPayOrderVO;
import com.zh.mediapojo.vo.ReserveOrderVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    @Insert("INSERT INTO hospital_order(name,sex,idCard,phone,reserve_time" +
            ",create_time,description,price,sid,doctor_id,order_id,uid)" +
            "values (#{name},#{sex},#{idCard},#{phone},#{reserveTime}" +
            ",#{createTime},#{description},#{price}," +
            "#{sid},#{doctorId},#{orderId},#{uid}                    )")
    void insert(Order order);

    @Update("update hospital_order set status=1 where order_id=#{tradeNo}")
    void updateOrderStatus(String tradeNo);
    @Select("select status from hospital_order where order_id=#{tradeNo}")
    String selectOrderStatus(String outTradeNo);
    @Select("select * from hospital_order where uid=#{uid} and status='0' ")
    List<Order> selectOrderByUid(Integer uid);

    List<ReserveOrderVO> selectOrderInfo(@Param("userId") Long userId);

    @Select("select id,order_id did,reserve_time  from hospital_order where status='0' and NOW()-create_time>=#{time} ")
    List<NotPayVO> selectNotPayOrder(LocalDateTime time);

    @Update("update hospital_order set status='2' where id=#{id}")
    void updateNotPayOrderStatus(Long id);

//    @Select("select order_id,price from hospital_order where id=#{id}")
//    PayNotPayOrderVO selectOrderId(Long id);
    @Select("select price from hospital_order where id=#{id}")
    Integer selectOrderPrice(Long id);

    @Select("select doctor_id,price,reserve_time from hospital_order where id=#{id} and status=0")
    PayNotPayOrderVO selectOrder(Long id);

    @Update("update hospital_order set order_id=#{orderId} where id=#{id}")
    void updateOrderId(Long id, String orderId);
}
